﻿using System;

namespace _1221_split_a_string_in_balanced_strings
{
    class Program
    {
        static void Main (string[] args)
        {
            string str = "LLRR";
            Console.WriteLine (BalancedStringSplit1 (str));
        }
        public static int BalancedStringSplit1 (string s)
        {
            int Rsum = 0;
            int Lsum = 0;
            int count = 0;

            for (int i = 0;i < s.Length;i++)
            {
                if (s[i] == 'R') Rsum ++;
                else Lsum++;
                if (Rsum == Lsum) count++;
            }

            return count;
        }
        public static int BalancedStringSplit (string s)
        {
            int count = 0;
            int num = 0;
            char c = s[0];
            for (int i = 0;i < s.Length - 1;i++)
            {
                if (s[i] == c) num++;
                else
                {
                    num--;
                    if (num == 0)
                    {
                        count++;
                        c = s[i + 1];
                    }
                }
            }
            count++;

            return count;
        }
    }
}
